package com.countryside.service.impl;

import com.countryside.mapper.CompanyWorkMapper;
import com.countryside.pojo.Company;
import com.countryside.pojo.CompanyWork;
import com.countryside.pojo.query.CompanyWorkQuery;
import com.countryside.service.CompanyWorkService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;

@Service
public class CompanyWorkServiceImpl implements CompanyWorkService {
    @Autowired
    CompanyWorkMapper companyWorkMapper;

    @Override
    public PageInfo<CompanyWork> listCompanyWorkBySearch(CompanyWorkQuery companyWorkQuery) {
        PageHelper.startPage(companyWorkQuery.getPageNum(),companyWorkQuery.getPageSize());
        return new PageInfo<CompanyWork>(companyWorkMapper.listCompanyWorkBySearch(companyWorkQuery));
    }

    @Override
    public int updateState(String id, int state) {
        return companyWorkMapper.updateState(id, state);
    }

    @Override
    public int deleteCompanyWork(String id) {
        return companyWorkMapper.deleteCompanyWork(id);
    }

    @Override
    public PageInfo<CompanyWork> listCompanyWork(CompanyWorkQuery companyWorkQuery) {
        PageHelper.startPage(companyWorkQuery.getPageNum(),companyWorkQuery.getPageSize());
        return new PageInfo<CompanyWork>(companyWorkMapper.listCompanyWork(companyWorkQuery));
    }

    @Override
    public List<CompanyWork> queryWorkByCompanyId(int id) {
        return companyWorkMapper.queryWorkByCompanyId(id);
    }

    @Override
    public List<CompanyWork> queryWorkByAddress(String address) {
        return companyWorkMapper.queryWorkByAddress(address);
    }

    @Override
    public Company queryCompanyByUserId(String userId) {
        return companyWorkMapper.queryCompanyByUserId(userId);
    }

    @Override
    public int companyWorkPublish(CompanyWork companyWork) {
        companyWork.setState(0);
        String localDateTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH-mm-ss"));
        companyWork.setPublishTime(localDateTime);
        return companyWorkMapper.companyWorkPublish(companyWork);
    }

    @Override
    public CompanyWork queryCompanyByCompanyId(String id) {
        return companyWorkMapper.queryCompanyByCompanyId(id);
    }


}
